<template>
	<view class="myBalance">
		<view class="weui-page__back">
			<image src="https://img.2024csnl.com/static/2.x/a38.png" mode="widthFix"></image>
		</view>
		<view class="topBox ">
			<view class="money">
				<view class="label">
					<text>总余额(￥)</text>
				</view>
				<view class="value">
					<text v-if="showMoney">{{ money }}</text>
					<text v-else>{{ '******' }}</text>
				</view>
			</view>
			<view class="btns">
				<view class="cell">
					<view
						class="btn is-chongzhi"
						@click="onSkip('/package/mine/topUp')">充值</view>
				</view>
				<view class="cell">
					<view
						class="btn"
						@click="onSkip('/business/pages/business_tab/balanceWithdrawal?pageType=余额提现')">提现</view>
				</view>
				<view class="cell" v-if="showType==1 && false">
					<view
						class="btn"
						@click="onSkip('/package/mine/transition/transition?tabsActive=0&person=true')">转赠</view>
				</view>
			</view>
			<view
				class="change"
				@click="changeMoneyShow">
				<template v-if="showMoney">
					<image src="https://img.2024csnl.com/static/2.x/a36.png" mode=""></image>
					<text>隐藏</text>
				</template>
				<template v-else>
					<image src="https://img.2024csnl.com/static/2.x/a37.png" mode=""></image>
					<text>显示</text>
				</template>
			</view>
		</view>
		
		<view class="page-thead">
			<text>余额变动明细</text>
		</view>
		
		<view class="details-box">
			<view class="tabs">
				<view class="item is-active">
					<text>全部</text>
				</view>
				<!-- <view class="item">
					<text>支出</text>
				</view>
				<view class="item">
					<text>收入</text>
				</view> -->
			</view>
			<view class="list">
				<view
					class="item"
					v-for="(item,i) in list"
					:key="i">
					<view class="cell">
						<!-- <view class="avatar">
							<image src="" mode=""></image>
						</view> -->
						<view class="left">
							<view class="name">{{ item.remark }}</view>
							<view class="time">{{item.createtime}}</view>
						</view>
						<view class="right">
							<view
								:class="{
									'money': true,
									'is-red': item.money > 0
								}">
								<text>{{ Number(item.money) }}</text>
							</view>
							<!-- <view class="yue">
								<text>余额 {{ '1000101' }}元</text>
							</view> -->
						</view>
					</view>
				</view>
				<view class="flex-center addressImgBox" v-if="list.length==0">
					<image src="https://wx.2024csnl.com/static/noData.png"></image>
					暂无数据~
				</view>
			</view>
			
			<view style="text-align: center;color: #999;" v-if="noMoreData&&list.length!=0">没有更多啦~</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyBalance
	} from "../../api/index.js"
	export default {
		data() {
			return {
				showType: null,
				noMoreData: false,
				money: '',
				list: [],
				pagenum: 1,
				showMoney: true
			}
		},
		onLoad(opt) {
			this.showType = opt.type
			console.log(opt.type)
			// this.onGetMyBalance()
		},
		onShow() {
			this.pagenum = 1
			this.onGetMyBalance()
		},
		onReachBottom() {
			this.pagenum += 1
			// console.log('触底了---',this.pagenum)
			this.onGetMyBalance('bottom')
		},
		methods: {
			async onGetMyBalance(type) {
				const res = await getMyBalance('s=/ApiMy/moneylog', {
					pagenum: this.pagenum
				})
				const {
					data,
					money,
					status,
					msg
				} = res.data
				if (status == 1) {
					// console.log(res, "ffff",type)
					this.money = money
					type == 'bottom' ? this.list.push(...data) : this.list = data
					this.pagenum != 1 && data.length == 0 ? this.noMoreData = true : this.noMoreData = false
				} else {
					this.showToast(msg)
				}
			},
			changeMoneyShow () {
				this.showMoney = !this.showMoney
			}
		}
	}
</script>

<style lang="scss" scoped>
	.myBalance {
		min-height: 100vh;
	}
	
	.topBox {
		background: url('https://img.2024csnl.com/static/2.x/a50.png') center center no-repeat;
		background-size: 100% 100%;
		position: relative;
		margin: 0 30rpx 80rpx;
		padding: 40rpx;
		top: 80rpx;
		border-radius: 20rpx;
		.change {
			position: absolute;
			right: 0;
			top: 0;
			padding: 30rpx 30rpx;
			display: flex;
			align-items: center;
			image {
				display: block;
				width: 40rpx;
				height: 40rpx;
				margin-right: 4rpx;
			}
			text {
				color: #999;
			}
		}
		.money {
			position: relative;
			padding: 0 20rpx;
			.label {
				line-height: 40rpx;
				font-size: 30rpx;
				color: #999;
			}
			.value {
				line-height: 80rpx;
				font-size: 56rpx;
				color: #41644A;
				font-weight: bold;
			}
		}
		.btns {
			display: flex;
			align-items: center;
			margin-top: 20rpx;
			.cell {
				flex: 1;
			}
			.btn {
				height: 80rpx;
				line-height: 80rpx;
				border-radius: 80rpx;
				margin: 20rpx;
				background: #41644A;
				text-align: center;
				font-size: 34rpx;
				font-weight: bold;
				color: #ffffff;
				&.is-chongzhi {
					background: -webkit-linear-gradient(left, #2D4834, #FFA47B);
				}
			}
		}
	}
	
	.page-thead {
		line-height: 100rpx;
		padding: 0 30rpx;
		font-size: 30rpx;
		color: #999;
	}
	
	.details-box {
		margin: 0 30rpx;
		background: #ffffff;
		border-radius: 20rpx;
		.tabs {
			display: flex;
			align-items: center;
			.item {
				position: relative;
				&.is-active {
					&:before {
						visibility: visible;
					}
					text {
						color: #2D4834;
						font-weight: bold;
					}
				}
				text {
					display: block;
					position: relative;
					z-index: 2;
					height: 100rpx;
					line-height: 100rpx;
					padding: 0 40rpx;
					font-size: 32rpx;
					color: #999;
				}
				&:before {
					content: '';
					position: absolute;
					z-index: 0;
					left: 20rpx;
					top: 60rpx;
					width: 120rpx;
					height: 18rpx;
					border-radius: 20rpx;
					background: -webkit-linear-gradient(left, #FDD69F, #ffffff);
					visibility: hidden;
				}
			}
		}
		.list {
			border-top: 1px solid #eeeeee;
			margin: 0 20rpx;
			.item {
				& + .item {
					border-top: 1px solid #eeeeee;
				}
				.cell {
					display: flex;
					// align-items: center;
					padding: 30rpx 0;
				}
				.avatar {
					image {
						display: block;
						width: 100rpx;
						height: 100rpx;
						background: #eeeeee;
						border-radius: 50%;
					}
				}
				.left {
					max-width: 60vw;
					margin: 0 60rpx 0 0;
					.name {
						line-height: 40rpx;
						font-size: 30rpx;
						font-weight: bold;
						word-break: break-all;
						margin: 0 0 10rpx;
					}
					.time {
						line-height: 40rpx;
						color: #999;
					}
				}
				.right {
					flex: 1;
					text-align: right;
					.money {
						line-height: 40rpx;
						font-size: 34rpx;
						font-weight: bold;
						white-space: nowrap;
						&.is-red {
							color: #E76730;
							&:before {
								content: '+';
							}
						}
					}
					.yue {
						line-height: 40rpx;
						color: #999;
					}
				}
			}
		}
	}
</style>